#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2021/9/12 21:48
# @Author : lenovo
# @Email : 26541796406@qq.com
# @File : knowledge_page.py
# @Project : crm
"""知识添加页面"""
from selenium.webdriver.common.by import By
from time import sleep
from page.base_page import BasePage
from utils.util import HS3
from selenium.webdriver.common.alert import Alert
class AddKnowledge(BasePage):
    url = "{}/crm3/index.php?m=knowledge".format(HS3)
    """定义定位器"""
    # 创建定位器
    title_locator = (By.ID, 'title')  # 知识标题
    content_locator = (By.XPATH, '/html/body')  # 知识内容
    knowledge_submit_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td/input[1]')  # 保存按钮
    input_locator = (By.ID,'check_all')  # 全选input
    del_locator = (By.LINK_TEXT,'删除')  # 删除按钮
    add_locator = (By.XPATH,'/html/body/div[5]/div[3]/div[2]/div/div[2]/a')  # 新建知识
    # 具体操作
    def add_knowledge(self):
        """点击新建知识"""
        self.driver.find_element(*self.add_locator).click()
    def title(self,title):
        """输入标题"""
        self.driver.find_element(*self.title_locator).send_keys(title)
    def content(self,content):
        """输入内容"""
        self.driver.find_element(*self.content_locator).send_keys(content)
    def submit(self):
        """提交保存"""
        self.driver.find_element(*self.knowledge_submit_locator).click()
    def frame_to(self):
        """切换页面到内容"""
        self.driver.switch_to.frame(self.driver.find_element_by_class_name('ke-edit-iframe'))
    def parent_to(self):
        """切换页面到最外层"""
        self.driver.switch_to.parent_frame()
    def del_knowledge(self):
        """删除所有的知识"""
        self.driver.find_element(*self.input_locator).click()
        sleep(1)
        self.driver.find_element(*self.del_locator).click()
        alert = Alert(self.driver)
        alert.accept()